package com.sanjiahantang.youjiaclient.module.match.views.impl;

import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.sanjiahantang.youjiaclient.R;
import com.sanjiahantang.youjiaclient.base.BaseMvpActivity;
import com.sanjiahantang.youjiaclient.module.match.adapters.MatchListAdapter;
import com.sanjiahantang.youjiaclient.module.match.presenters.MatchPresenter;
import com.sanjiahantang.youjiaclient.module.match.views.MatchView;

/**
 * Created by zy on 2017/10/16.
 */

public class MatchListActivity extends BaseMvpActivity<MatchView,MatchPresenter> implements MatchView, View.OnClickListener {

    private RecyclerView recyclerView;
    private SwipeRefreshLayout refreshLayout;

    @Override
    public void showProgress() {
        super.showProgress($this);
    }

    @Override
    public MatchPresenter initPresenter() {
        return new MatchPresenter();
    }

    @Override
    public void initView() {
        setContentView(R.layout.activity_match_list);
        findViewById(R.id.fl_Left).setOnClickListener(this);
        TextView title = (TextView) findViewById(R.id.title);
        title.setText("搭配");

        refreshLayout = (SwipeRefreshLayout) findViewById(R.id.refreshLayout);
        recyclerView = (RecyclerView) findViewById(R.id.recyclerView);

        presenter.setPullListener(new PullListener(){

            @Override
            public void pullToRefresh(MatchListAdapter adapter) {
                recyclerView.setAdapter(adapter);
                recyclerView.setLayoutManager(new LinearLayoutManager($this));
                refreshLayout.setRefreshing(false);
                if ($this != null)
                hideProgress();
            }

            @Override
            public void pullToAppend() {

            }
        });

        refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                presenter.loadMatchList($this);
            }
        });

    }

    @Override
    public void initData() {
        presenter.loadMatchList($this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.fl_Left:
                finish();
                break;
        }
    }
}
